import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class CollegeMessageServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {
        String college_uname=request.getParameter("college_uname");
        String college_pwd=request.getParameter("college_pwd");
        
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();


        Class.forName("oracle.jdbc.driver.OracleDriver");
       Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 
       String str="";
       Statement stmt=con.createStatement();
          ResultSet rs5=stmt.executeQuery("select company_name from company_register");
         while(rs5.next())
		  {
		  String s=rs5.getString("company_name");
		  str=str+"<option value="+s+">"+s+"</option>";

		  }

       ResultSet rs = stmt.executeQuery("SELECT *FROM college_login WHERE college_uname='"+college_uname+"' and college_pwd='"+college_pwd+"'");


         if(rs.next())

         {
           
         ResultSet rs2=stmt.executeQuery("SELECT *FROM college_register WHERE  college_uname='" +college_uname+ "'");

    if(rs2.next())
     {
             String college_name = rs2.getString(1);
             String university = rs2.getString(2);
             String college_code = rs2.getString(3);                                    
     
     out.println("<html>");
     out.println("<html><head><script src='show.js'></script></head> ");
     
       
      out.println("<body background=\"t7.jpg\" onload='showCompany()'>"); 
out.println("<div><div style='float:left'>");
out.println("<form action='index.html'>");
 out.println("<input type='submit' value='home'/></form></div>");
out.println("<div style='float:right'>");
 out.println("<form action='student-login.html'>");
            out.println("<input type='submit'  value='logout'/></form></div>");

     out.println("<center>");    
     
     out.println(" <br><h1> <font color=\"cyan\"> "+college_name+" </font> </h1> ");

     out.print("<br> <b> <font color=\"white\"> Affiliated to </font> <font color=\"lawngreen\"> "+university+" </font> </b>");
out.print("&nbsp &nbsp &nbsp <b> <font color=\"white\"> College-Code : </font> <font color=\"lawngreen\">"+ college_code+ "</font></b>");

   out.println("<br> <br> <br> <b><marquee text=\"red\" behavior=\"alternate\"><font size=\"3\" color=\"red\"> Placement Assistance for </font> <font color=\"cyan\" size=\"4\"> "+college_name+"</font> </marquee> </b>");

     out.println("</center>");   
out.println("<br><br><br>");
out.println("<div style='float:right;width:45%'>");
            out.println("<form method='post' action='ccs'>");
            out.println(" <font color=\"white\">search  company  </font><select name='company' id='company' onload='showCompany()'><option value='--select--'>--select--</option>"+str+"</select>  <input type='submit' value='search'/></form>"); 
         out.println("</div>"); 

  out.println("<form action='cms2' method='post'>");
  out.println("<input type='submit' value='updates'></form>");
ResultSet rs3 = stmt.executeQuery("SELECT *FROM message WHERE college_name='mipgs'");
 while(rs3.next())
{
out.println("<table color='white' >");
out.println("<tr><td>rs3.getString(college_name)</td><td>rs3.getString(message)</td><td>rs3.getString(send_date)</td></tr>");
out.println("</table>");
}
     
     
     out.println("</body>");

     out.println("</html>");        

     }
 

         else

       {
   
           out.println("<html>");
     
           out.println("<body background=\"t7.jpg\">");

           out.println(" <font color=\"white\" size=\"4\"> ");
        
           out.println("<br><br> <b> Invalid Username/password </b>");
  

           out.println("<br><br> <b> <a href=\"/webapp/college-login.html\"> <font color=\"cyan\"> Click </font> </a> here to reenter the Correct Username and Password </b>");

           out.println(" </font> ");
    
           out.println("</body>");

           out.println("</html>");        
  
        }

         }
       }
 
    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 